<template>
    <div>
        <ly-dialog v-model="dialogVisible" :title="loadingTitle" width="560px" :before-close="handleClose">
            <el-form :inline="false" :model="formData" :rules="rules" ref="rulesForm" label-position="right" label-width="auto">
                <el-form-item label="编号：" prop="sn">
                    <el-input v-model="formData.sn"></el-input>
                </el-form-item>
                <el-form-item label="门店名称" prop="house_name">
                    <el-input v-model="formData.house_name"></el-input>
                </el-form-item>
                <el-form-item label="门店类型" prop="house_type">
                    <el-input v-model="formData.house_type"></el-input>
                </el-form-item>
                <el-form-item label="社区名称" prop="level">
                    <el-input v-model="formData.level"></el-input>
                </el-form-item>
                <el-form-item label="社区地址" prop="address">
                    <el-input v-model="formData.address"></el-input>
                </el-form-item>
                <el-form-item label="住户数量" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="离门店距离" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="门禁VD" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="出入口数量" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="门禁锁点数量" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="投放时间" prop="house_man">
                    <el-input v-model="formData.house_man"></el-input>
                </el-form-item>
                <el-form-item label="经度" prop="house_lat">
                    <el-input v-model="formData.house_lat"></el-input>
                </el-form-item>
                <el-form-item label="维度" prop="house_lng">
                    <el-input v-model="formData.house_lng"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <el-button @click="handleClose" :loading="loadingSave">取消</el-button>
                <el-button type="primary" @click="submitData" :loading="loadingSave" :disabled="loadingTitle=='详情'">确定</el-button>
            </template>
        </ly-dialog>
    </div>
</template>

<script>
    import {mallGoodsSpeciesAdd,mallGoodsSpeciesEdit} from "@/api/api";
    import LyDialog from "../../../components/dialog/dialog";
    export default {
        emits: ['refreshData'],
        name: "addModuleGoodsType",
        components: {LyDialog},
        data() {
            return {
                dialogVisible:false,
                loadingSave:false,
                loadingTitle:'',
                formData:{
                    name:"",
                    unit:"",
                    sort:0
                },
                rules:{
                    name: [
                        {required: true, message: '请输入橱窗名称',trigger: 'blur'}
                    ],
                }
            }
        },
        methods:{
            handleClose() {
                this.dialogVisible=false
                this.loadingSave=false
                this.formData = {
                    name:"",
                    unit:"",
                    sort:0
                }
                this.$emit('refreshData')
            },
            addModuleFn(item,flag,category) {
                this.loadingTitle=flag
                this.dialogVisible=true
                if(item){
                    this.formData=item
                }
                this.formData.category=category
            },
            submitData() {
                this.$refs['rulesForm'].validate(obj=>{
                    if(obj) {
                        this.loadingSave=true
                        let param = {
                            ...this.formData
                        }
                        if(this.formData.id){
                            mallGoodsSpeciesEdit(param).then(res=>{
                                this.loadingSave=false
                                if(res.code ==2000) {
                                    this.$message.success(res.msg)
                                    this.handleClose()
                                    this.$emit('refreshData')
                                } else {
                                    this.$message.warning(res.msg)
                                }
                            })
                        }else{
                            mallGoodsSpeciesAdd(param).then(res=>{
                                this.loadingSave=false
                                if(res.code ==2000) {
                                    this.$message.success(res.msg)
                                    this.handleClose()
                                    this.$emit('refreshData')
                                } else {
                                    this.$message.warning(res.msg)
                                }
                            })
                        }
                    }
                })
            }
        }
    }
</script>
<style scoped>
    .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409EFF;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 128px;
      height: 128px;
      line-height: 128px;
      text-align: center;
    }
    .avatar {
      width: 128px;
      height: 128px;
      display: block;
    }
</style>

